﻿/*----------------------------------------------------------------
 * 
 * 版权所有：Copyright (C) 2013
 * 
 * 文件名：DbContextFactory.cs
 * 文件功能描述：
 * 
 * 
 * 作 者：zhangq
 * 邮 箱：ifunnyface@outlook.com
 * 日 期：2013-01-23 09:10:09
 * 
 * 
 * 修改标识： Author
 * 修改描述： 相关描述
 * 
 * ---------------------------------------------------------------- */

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace Manager
{

    /// <summary>
    /// DbContext创建工厂
    /// </summary>
    public class DbContextFactory : Disposable,IDbContextFactory
    {

        /// <summary>
        /// 
        /// </summary>
        private readonly EFDBContext context;

        public DbContextFactory()
        {
            // the context is new()ed up instead of being injected to avoid direct dependency on EF
            // not sure if this is good approach...but it removes direct dependency on EF from web tier
            context = new EFDBContext();
            //context.Configuration.ProxyCreationEnabled = false;
        }

        /// <summary>
        /// DbContext
        /// </summary>
        /// <returns>DbContext实例</returns>
        public EFDBContext GetDbContext()
        {
            return context;
        }


        /// <summary>
        /// 资源释放
        /// </summary>
        protected override void DisposeCore()
        {
            if (context != null)
            {
                context.Dispose();
            }
        }

         
    }

}